#!/bin/bash

flink=/opt/module/flink-yarn/bin/flink
jar=/opt/gmall_0924/gmall-realtime-1.0-SNAPSHOT.jar

apps=(
com.atguigu.gmall.realtime.app.dwd.DwdLogApp
com.atguigu.gmall.realtime.app.dwd.DwdDbApp
com.atguigu.gmall.realtime.app.dwm.DwmUvApp
com.atguigu.gmall.realtime.app.dwm.DwmUserJumpDetailApp
com.atguigu.gmall.realtime.app.dwm.DwmOrderWideAppCacheAsync
com.atguigu.gmall.realtime.app.dwm.DwmPaymentWideApp
com.atguigu.gmall.realtime.app.dws.ProductStatsApp
)

# 获取正在运行的所有apps 得到一个数组
running_app_names=`$flink list -r 2>/dev/null | awk '/RUNNING/ {print \$(NF-1)}'`

# 遍历数组
for app in ${apps[*]} ; do
    # 要启动的app的名字
    app_name=`echo $app | awk -F . '{print \$NF}'`
    if [[ "${running_app_names[@]}" =~ ${app_name} ]]; then
        echo "$app_name 已经启动, 无序重复启动"
    else
        echo "开始启动 $app_name"
        $flink run -d -c $app $jar
    fi
done